import axios from 'axios'
import apis from '../../http/apis/apis'

export default {
    namespaced: true,
    state: {
        adminsListData: {
            pages: 0,
            total: 0,
            admins: []
        },
        pageSize: 5,
        currentPage: 1,
    },
    mutations: {
        changeadminsListData(state, newData) {
            state.adminsListData = newData;
        },
        changepageSize(state, newpageSize) {
            state.pageSize = newpageSize
        },
        changecurrentPage(state, newcurrentPage) {
            state.currentPage = newcurrentPage
        }
    },
    actions: {
        //获取普通管理员列表
        async getAdmins(context) {
            const { data } = await apis.admins.getAdmins({
                currentPage: context.state.currentPage,
                pageSize: context.state.pageSize,
            });
            if (data.status) {
                context.commit('changeadminsListData', data.data)
            }
        },
        //冻结账号
        async freezeAdmins(context, _id) {
            await apis.admins.freezeAdmins(_id);
        },
        //解除冻结状态
        async exposureFreezeAdmins(context, _id) {
            await apis.admins.exposureFreezeAdmins(_id);
        },
        //修改密码
        async updatePassword(context, params) {
            await apis.admins.updatePassword(params);
        }
    }
}